<script>
	$(function(){
            
            $('#taskTemplateModal').modal('show');
            
            $("#btnNewTemplate").click(function(){ 
                $('#taskTemplateModal').modal('hide');
                $("#modalholder").load("<?php echo $this->SE_path . '/usertasks/showtask?addtemplate=true' ?>");
            });
            
            loadTable();
	});

	function loadTable()
	{

		var users = $.parseJSON(<?php echo "'" . $this->users . "'" ?>);
		

		$("#tasktable").html("");
		
		   $.getJSON("<?php echo $this->SE_path . '/usertasks/gettemplates' ?>", 

                   function(data)  {
                   	 $.each(data, function(key, val) {
                   		 $("<tr>")
                   		.append($("<td>").append($("<span>").html(val)))
                   		.append($("<td>").append($("<a>").html("uitvoeren").click(function(){
                   			 $('#taskTemplateModal').modal('hide');
                   			 loadIntoModalholder("<?php echo $this->SE_path . '/usertasks/showtask' ?>",  {selectedUsers:users,templatename:val,fromTemplate:true});
                       	})))
                   		.append($("<td>").append($("<a>").html("bewerken").click(function(){
                   			 $('#taskTemplateModal').modal('hide');
                   			 loadIntoModalholder("<?php echo $this->SE_path . '/usertasks/showtask' ?>",  {templatename:val,editTemplate:true});
                       	})))
                   		.append($("<td>").append($("<a>").html("verwijderen").click(function(){
                   			 var r = confirm("Verwijder takentemplate: " + val);
                                if (r==true)
                                {
                                	
                                    $.post("<?php echo $this->SE_path . '/usertasks/removetasktemplate' ?>", {templatename:val},function(){
                                    	loadTable();
                                    });
                                }
                   		})))
                   		.appendTo($("#tasktable"));
						
                   	  });
                   });
	}

	

</script>

<div
	class="hide SEsupermodal"
	id="taskTemplateModal">
	<div>
		<div class="modal-header addminwidth">
			<a
				class="close"
				data-dismiss="modal">×</a>
			<h3 id="modaltitle">Taak templates beheren</h3>
		</div>

		<div class="modal-body">

			<section id="tasktemplate">

				<div class="control-group">

					
					<table class="table" id="tasktable">
					
					</table>

				</div>

				<div class="control-group">

					<a
						href="#"
						id="btnNewTemplate"
						name="btnNewTemplate"
						class="btn btn-primary">Maak nieuwe template</a>

				</div>

			</section>

		</div>


		<div class="modal-footer">
			<a
				href="#"
				class="btn"
				data-dismiss="modal">Sluiten</a>
		</div>

	</div>
</div>
